<template>
  <view class="md-icon" :style="{ width: width + 'rpx', height: height + 'rpx' }" @click="onClick">
    <image
      class="image"
      :mode="mode || 'aspectFill'"
      :style="{ borderRadius: radius + 'rpx' }"
      :src="url ? url : `/static/${type === 'icon' ? 'icons' : 'images'}/${name}.png`" />
    <!-- 默认插槽 -->
    <view class="content" :style="customStyle">
      <slot></slot>
    </view>
  </view>
</template>

<script setup lang="ts">
const emit = defineEmits(['click']);
defineProps({
  width: {
    type: String,
    default: '38',
  },
  height: {
    type: String,
    default: '38',
  },
  name: String,
  url: String,
  type: {
    type: String, // icon | bg
    default: 'icon',
  },
  mode: {
    type: String, // scaleToFill | aspectFit | aspectFill | widthFix | heightFix | top | bottom | left | right | top left | top right | bottom left | bottom right
  },
  customStyle: Object,
  radius: {
    type: String,
    default: '0',
  },
});

const onClick = (e: any) => emit('click', e);
</script>

<style lang="scss" scoped>
.md-icon {
  position: relative;
  .image,
  .content {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
  }
  .content {
    z-index: 1;
  }
}
</style>
